package com.nth.rooster.core.helper;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.nth.rooster.core.entities.RamCircles;
import com.nth.rooster.core.entities.RamUsers;
import com.nth.rooster.core.pojo.CircleBeans;
import com.nth.rooster.core.pojo.User;

public class Mapper {

	public static RamCircles mapCircleFromPojo(CircleBeans circleBeans, RamCircles ramCircles,Long userID) {

		
		if (ramCircles == null) {
			ramCircles = new RamCircles();	
		}

		if (circleBeans.getCircleID() != null) {
			ramCircles.setCircleID(circleBeans.getCircleID());
			
		}else{
			ramCircles.setCreatedBy(userID);
			ramCircles.setCreatedDate(new Date());
		}

		if (circleBeans.getCircleTitle() != null) {
			ramCircles.setCircleName(circleBeans.getCircleTitle());
		}

		if (circleBeans.getCircleDescrition() != null) {
			ramCircles.setCircleDescription(circleBeans.getCircleDescrition());
		}
		
		Set<RamUsers> listOfRamUsers = null;
		if (circleBeans.getAdmins() != null) {
			listOfRamUsers = new HashSet<RamUsers>();
			for (User user : circleBeans.getAdmins()) {
				RamUsers ramUsers = new RamUsers();
				ramUsers.setUserId(user.getUserID());
				listOfRamUsers.add(ramUsers);
			}
		}
		//ramCircles.setRamUsers(listOfRamUsers);
		ramCircles.setModifiedBy(userID);
		ramCircles.setModifiedDate(new Date());

		return ramCircles;

	}

}
